package com.ls.jpushMessageClient;

import cn.jiguang.common.ClientConfig;
import cn.jiguang.common.connection.HttpProxy;
import cn.jpush.api.JPushClient;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 目前发现一个JPushClient可能同时处理消息数量不够多，可以记录当前这个实体所处理的消息数量，达到动态的设置jpushClient
 * 针对大并发会有用
 */
public class JPushClientCustom extends JPushClient {
    private AtomicInteger count=new AtomicInteger(0);
    private long last_handler_time=0; //最后一次使用时间,每个60分钟定时检测长期不使用的实例，关闭掉
    public int getCount(){
        return count.get();
    }
    public long getLast_handler_time(){
        return last_handler_time;
    }
    public void incr(){
        last_handler_time=System.currentTimeMillis();
        count.incrementAndGet();
    }
    public void decr(){
        last_handler_time=System.currentTimeMillis();
        if(count.get()>0)
            count.decrementAndGet();
    }
    public JPushClientCustom(String masterSecret, String appKey) {
        super(masterSecret, appKey);
    }

    public JPushClientCustom(String masterSecret, String appKey, HttpProxy proxy, ClientConfig conf) {
        super(masterSecret, appKey, proxy, conf);
    }
}
